local Object = {}
Object.__index = Object

function Object:ctor(scene, property, data)
    local _ins = {}
    setmetatable(_ins, self)

    _ins._scene = scene
    _ins:initProperty(property)
    _ins:initData(data, is_new_game)
    _ins:initView()

    return _ins
end

-- 初始化属性
function Object:initProperty(property)
    if type(property) ~= "table" then
        return
    end
    self._property = {}
    for k, v in pairs(property) do
        self._property[k] = v
    end
end

-- 初始化数据
function Object:initData(data)
    if type(data) ~= "table" then
        return
    end
    self._data = {}
    for k, v in pairs(data) do
        self._data[k] = v
    end
end

-- 初始化界面
function Object:initView()
end

-- 导出数据
function Object:exportData()
    local data = {}
    for k, v in pairs(self._data) do
        data[k] = v
    end
    return data
end

-- 添加到显示列表
function Object:addToDisplay(x, y)
    if self._sprite and self._scene then
        self._scene:addChild(self._sprite)
    end
    if x then
        self:setPosition(x, y)
    end
    -- local draw_node = cc.DrawNode:create()
    -- self._sprite:addChild(draw_node)
    -- local w, h = self:getSize()
    -- draw_node:drawRect(cc.p(0,0), cc.p(0, h), cc.p(w , h), cc.p(w, 0), cc.c4f(0.47, 0.23, 0.11, 0.6))
end

-- 从显示列表移除
function Object:removeSelf()
    self:stopLoop()
    if self._sprite then
        self:stopAnimate()
        self._sprite:removeFromParent()
        self._sprite = nil
    end
end

-- 执行动画
function Object:runAnimate()
    if self._sprite and self._animate then
        self._sprite:stopAllActions()
        self._sprite:runAction(self._animate)
    end
end

-- 停止动画
function Object:stopAnimate()
    if self._sprite then
        self._sprite:stopAllActions()
    end
end

-- 停止循环
function Object:stopLoop()
end

-- 界面显示相关
function Object:getSprite()
    return self._sprite
end

function Object:setSprite(val)
    if val ~= nil then
        self._sprite = val
    end
end

function Object:setDepth(v)
    if self._sprite then
        self._sprite:setLocalZOrder(v)
    end
end

function Object:getSize()
    if self._sprite then
        local size = self._sprite:getContentSize()
        return size.width, size.height
    end
end

function Object:getPosition()
    if self._sprite then
        return self._sprite:getPosition()
    end
end

function Object:setPosition(x, y)
    if self._sprite then
        if type(x) == "table" then
            self._sprite:setPosition(x)
        elseif type(x) == "number" and type(y) == "number" then
            self._sprite:setPosition(x, y)
        end
    end
end

function Object:getAnimate()
    return self._animate
end

function Object:setAnimate(val)
    self._animate = val
end

-- 静态属性
function Object:getName()
    return self._property.name
end

-- 动态数据
function Object:getType()
    return self._data.type
end

function Object:getMaxBlood()
    return self._data.max_blood
end

function Object:getBlood()
    return self._data.blood
end

function Object:setBlood(val)
    self._data.blood = val
end

function Object:getAttack()
    return self._data.attack
end

function Object:getMoveSpeed()
    return self._data.move_speed
end

function Object:setMoveSpeed(val)
    self._data.move_speed = val
end

return Object
